package test.juc.executetask;

import java.util.concurrent.CompletableFuture;

public class ExecuteTaskOrderlyTest3 {

    public static void main(String[] args) {
        // 创建CompletableFuture对象
        CompletableFuture<Void> future1 = CompletableFuture.runAsync(new MySecThread("T1"));

        // 等待线程T1完成
        future1.join();

        // 创建CompletableFuture对象
        CompletableFuture<Void> future2 = CompletableFuture.runAsync(new MySecThread("T2"));

        // 等待线程T2完成
        future2.join();

        // 创建CompletableFuture对象
        CompletableFuture<Void> future3 = CompletableFuture.runAsync(new MySecThread("T3"));

        // 等待线程T3完成
        future3.join();
    }

}
class MySecThread implements Runnable {
    private String name;

    public MySecThread(String name) {
        this.name = name;
    }

    @Override
    public void run() {
        try {
            // 模拟执行任务
            Thread.sleep(1000);
            System.out.println(name + " is Running.");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}